package com.example.base.base

import android.os.Bundle
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.LayoutRes
import androidx.appcompat.app.AppCompatActivity

open class BaseActivity : AppCompatActivity {

    private var contentLayoutId: Int? = null

    constructor(): super()
    constructor(@LayoutRes contentLayoutId: Int): super() {
        this.contentLayoutId = contentLayoutId
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        contentLayoutId?.apply { setContentView(this) }
    }

    protected val requestMultiplePermissions =
        registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { permissions: Map<String, Boolean> ->
            // Do something if some permissions granted or denied
            permissions.entries.forEach {
                // Do checking here
            }
        }

    protected val requestPermissions =
        registerForActivityResult(ActivityResultContracts.RequestPermission()) {
            // Do checking here
        }

}

